<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>美嘉饲料</title>
<link href="<%=basePath%>skin/css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%=basePath%>skin/js/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="<%=basePath%>skin/js/common.js"></script>
<script type="text/javascript" src="<%=basePath%>skin/js/jraty/jquery.raty.min.js"></script>
<script type="text/javascript">
	$().ready(function(){
		$("#menu_order").attr("class","select");
		var starScore = 20; // 一颗星 20分
		//初始化打分
		$(".score").raty({
			path: "<%=basePath%>skin/images/jraty/",
			starHalf: "star-half-big.png",
			starOff: "star-off-big.png",
			starOn: "star-on-big.png",
			width:250,
			hintList:["不满意", "不满意", "基本满意", "比较满意", "非常满意"],
			click:function(score, evt) {
				var realScore = score*starScore;
				$(this).parent().parent().parent().parent().parent().find("input[name=score]").val(realScore);
			}
		});
	});

	function showComment(productId, commentClass){
		$("."+commentClass).hide();
		$("#"+productId).show();
	}
</script>
</head>
  
<body>
<div class="nb-smt"></div>
<div id="container" class="wkg">
<c:import url="/layouts/top.jsp" />
<div id="content">
        <c:import url="/layouts/head.jsp" />
        <div id="main">
        	<c:import url="../left.jsp" />
			<div id="myRight">
			<div class="myRightTitle">
				<div class="mrtl">
					商品评价
				</div>
				<div class="clear"></div>
			</div>
			<div class="myRightContent">
				<table id="my1Table" cellspacing="0" cellpadding="0">
					<tr>
						<td>商品</td>
						<td>单价</td>
						<td>数量</td>
						<td>小计</td>
						<td>评价状态</td>
					</tr>
					<c:forEach items="${order.orderItems }" var="orderItem" varStatus="status">
						<tr>
							<td>${orderItem.name }</td>
							<td><fmt:formatNumber value="${orderItem.price }" pattern="0.00"/></td>
							<td><fmt:formatNumber value="${orderItem.quantity }" pattern="0"/></td>
							<td><fmt:formatNumber value="${orderItem.subtotal }" pattern="0.00"/></td>
							<td>
							<c:set var="hasCommented" value="false"/>
							<c:forEach items="${order.comments }" var="comment">
								<c:if test="${comment.product.id == orderItem.product.id }">
									<c:set var="hasCommented" value="true"/>
								</c:if>
							</c:forEach>
							<c:choose>
								<c:when test="${hasCommented }">
									已评价
								</c:when>
								<c:otherwise>
									<input type="button" class="btnSub" value="发表评价" onClick="showComment(${orderItem.product.id }, 'comment')"/>
								</c:otherwise>
							</c:choose>
							</td>
						</tr>
						<tr id="${orderItem.product.id }"
						<c:choose>
						<c:when test="${status.first && !hasCommented }">style="display:block"</c:when>
						<c:otherwise>style="display:none"</c:otherwise>
						</c:choose> class="comment">
						<td>
							<form name="commentForm" method="post" action="<%=basePath%>member/comment/save.shtml">
							<input type="hidden" name="orderId" value="${order.id }" />
							<input type="hidden" name="productId" value="${orderItem.product.id }" />
							<input type="hidden" name="score"/>
							<table width="100%" cellspacing="0" cellpadding="0">
								<tbody>
	                            	<tr>
	                                	<td width="33%">评分:</td>
	                                    <td width="67%"><div class="score"></div></td>
	                                </tr>
	                                <tr>
	                                	<td>心得:</td>
	                                    <td>
	                                    	<textarea name="content" style="width: 100%;"></textarea>
	                                    </td>
	                                </tr>
	                                <tr>
	                                	<td colspan="2">
	                                		<c:choose>
												<c:when test="${status.last}"><input type="submit" class="btnSub" value="评价"/></c:when>
												<c:otherwise><input type="submit" class="btnSub" value="评价并继续"/></c:otherwise>
											</c:choose>
	                                	</td>
	                                </tr>
                                </tbody>
                            </table>
                            </form>
                         </td>
						</tr>
					</c:forEach>							
				</table>
			</div>
			</div>
        </div>
        <div class="clear"></div>
    </div>
</div>
<c:import url="/layouts/foot.jsp" />
</body>
</html>


